package com.example.zhilongzhang.constructionpayapp.http;


import android.content.Context;

import com.example.zhilongzhang.constructionpayapp.util.SpUtil;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

/**
 * 封装
 *
 *必须记住这里如何一直上传失败可以看方法5，在后面加一个POst
 */
public class HttpMethod extends HttpBase {
    static String BaseUrl1 = "http://47.105.99.166:21001";
    static String ZhaoUrl = "http://172.30.247.76:8080";
    public static String BaseUrl2 = "http://47.105.99.166:21001/platform/";

    public static int DefaultPageSize = 15;
    private static String Ashx= "Ashx.ashx";

    //用法1  带参数
    public static void getMethod1(int pageIndex, StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("pageIndex", String.valueOf(pageIndex));
        GetInterfaceData(Ashx, "getMethod1", map, callback);
    }

    //用法2 无参数
    public static void getMethod1(StringCallback callback) {
        GetInterfaceData(Ashx, "getMethod1", callback);
    }

    //用法3 无Token是必须要false,否则默认带Token
    public static void getMethod3(String phone, String password, String pushCode, StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("phone", phone);
        map.put("password", password);
        GetInterfaceData(Ashx, "getMethod3", map, callback, false);
    }
    //用法4  所有的都带Context可以用于取消HTTP
    public static void getMethod4(Context context, StringCallback callback) {
        GetInterfaceDataTag(context,Ashx, "getMethod4",callback);
    }

    //用法5 有时get不能使用时要主动加Post
    public static void getMethod5(String posts_Id, String parent_Id, StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("posts_Id", posts_Id);
        map.put("parent_Id", parent_Id);
        GetInterfaceData(Ashx, "getMethod5", map, callback,"post");
    }
    public static void getQrCode(Context context,String totalFee, StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("totalFee", totalFee);
        map.put("format", "json");
        GetInterfaceDataTag(context,SpUtil.getQRImgUrl()+SpUtil.getShopId(), "getQrCode", map, callback,false);
    }
    public static void getQrCode2(Context context,String totalFee,String  remark1,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("totalFee", totalFee);
        map.put("remark1", remark1);
        map.put("format", "json");
        GetInterfaceDataTag(context,SpUtil.getQRImgUrl()+SpUtil.getShopId(), "getQrCode", map, callback,false);
    }
    public static void paymentNotify(Context context,String orderId,StringCallback callback) {
        GetInterfaceDataTag(context,SpUtil.getQRPayUrl()+orderId, "paymentNotify",callback);
    }

    public static void checkState(Context context,String paymentCode,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("paymentCode", paymentCode);
        GetInterfaceDataTag(context,BaseUrl2+"datalist/checkState", "checkState",map,callback,"get");
    }
    public static void printUpdate(String paymentCode,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("paymentCode", paymentCode);
        GetInterfaceData(BaseUrl2+"datalist/printUpdate", "printUpdate",map,callback,"get");
    }

    public static void resetPassword(String username,String oldPassword,String newPassword, StringCallback callback) {
        Map<String, Object> baseMap = getBasePostBody();
        Map<String, String> map = new HashMap<>();
        map.put("username", SpUtil.getUserName());
        map.put("oldPassword", oldPassword);
        map.put("password", newPassword);
        map.put("repassword", newPassword);
        map.put("access_token",SpUtil.getToken());
        baseMap.put("data", map);
        GetInterfaceStr(BaseUrl2+"user/changepw", "resetPassword", baseMap, callback);
    }

    public static Map<String, Object> getBasePostBody() {
        Map<String, Object> map = new HashMap<>();
//        map.put("approvalComments", "");
//        map.put("businessKey", "");
        map.put("operationType", "");
//        map.put("processAction", "");
        map.put("processDefinitionId", "");
//        map.put("processInstanceId", "");
        map.put("userid", SpUtil.getUserId());
        map.put("username", SpUtil.getUserName());
        return map;
    }
    public static void getdatalist(String userId,int page, StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("userId", userId);
        map.put("page",String.valueOf(page));
        map.put("payee", SpUtil.getUserId());
        map.put("limit", "15");
        GetInterfaceData(BaseUrl2+"datalist/getdatalist", "getdatalist", map, callback);
    }
    public static void security(StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("username", SpUtil.getUserName());
        map.put("access_token",SpUtil.getToken());
        GetInterfaceData(BaseUrl2+"user/security/"+SpUtil.getUserName(), "security", map, callback);
    }
    public static void savedatalist(String paymentCode,String moneyType,String paymentTime,String amount,String comments,String remitterName,String adress,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("paymentCode", paymentCode);//订单偏好
        map.put("payee",SpUtil.getUserId());//收款员ID
        map.put("deptId",SpUtil.getShopId());//公司ID
        map.put("username",SpUtil.getUserName());//收款员名字
        map.put("moneyType",moneyType);
        map.put("paymentTime",paymentTime);
        map.put("amount",amount);//钱数
        map.put("comments",comments);//备注
        map.put("remitterName",remitterName);//房主名字
        map.put("adress",adress);//房主地址
        GetInterfaceData(BaseUrl2+"datalist/savedatalist", "savedatalist", map, callback,"post");
    }
    public static void byDate(String year,String month,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("year",year);
        map.put("month",month);
        GetInterfaceData(BaseUrl2+"datalist/statistic/byDate", "byDate", map, callback);
    }
    public static void getAnalysis(String year,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("deptId",SpUtil.getShopId());
        map.put("year",year);
        GetInterfaceData(BaseUrl2+"analysis/getAnalysis", "getAnalysis", map, callback);
    }
    public static void getFiles(String deptid,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("deptid", deptid);
        GetInterfaceData(BaseUrl2+"dept/getFiles", "getFiles", map, callback);
    }
    public static void checkPayStates(String url,String paymentCode,String moneyType,String amount,String comments,String remitterName,String adress,String userid,String feeduration,String depSaveUrl,StringCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("url", url);//订单偏好
        map.put("paymentCode", paymentCode);//订单偏好
        map.put("payee",SpUtil.getUserId());//收款员ID
        map.put("deptId",SpUtil.getShopId());//公司ID
        map.put("username",SpUtil.getUserName());//收款员名字
        map.put("moneyType",moneyType);
        map.put("amount",amount);//钱数
        map.put("comments",comments);//备注
        map.put("remitterName",remitterName);//房主名字
        map.put("adress",adress);//房主地址
        map.put("userid",userid);
        map.put("feeduration",feeduration);
        map.put("depSaveUrl",depSaveUrl);
        GetInterfaceData(BaseUrl2+"datalist/checkPayStates", "checkPayStates", map, callback,"post");
    }

}
